package com.duan.config;

import com.duan.filter.TestFilter2;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;
import java.util.ArrayList;
import java.util.List;

/**
 * @author db
 * @version 1.0
 * @description FilterConfig
 * @since 2023/12/20
 */
@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean<TestFilter2> testFilter2(){
        FilterRegistrationBean<TestFilter2> filterFilterRegistrationBean = new FilterRegistrationBean<>();
        filterFilterRegistrationBean.setEnabled(true);    // 是否启动注入过滤器
        filterFilterRegistrationBean.setFilter(new TestFilter2());  // 设置过滤器
        filterFilterRegistrationBean.setOrder(1);         // 设置过滤器顺序  数字越小越靠前
        filterFilterRegistrationBean.setName("TestFilter2");    // 设置过滤器名字

        List<String> urlPatterns = new ArrayList<>();
        urlPatterns.add("/*");
        filterFilterRegistrationBean.setUrlPatterns(urlPatterns);  // 设置要过滤的路径

        return filterFilterRegistrationBean;
    }
}
